<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>艾家艾产品线上销售平台</title>
    <link rel="shortcut icon" href="../img/favicon.ico">
    <link rel="stylesheet" href="../css/reset.css"/>
    <link rel="stylesheet" href="../css/register-password.css"/>
    <script src="../them/jquery/jquery-1.7.2.js"></script>
    <script src="../them/jquery/jquery.cookie.js"></script>
</head>
<body>
<div class="box">
    <div class="header">
        <div class="header-logo">
            <div class="logo_b"></div>
            <div class="tittle">
                <p style="font-size: 32px;margin-bottom: 60px">注册艾家账号</p>
            </div>
        </div>
    </div>
    <div class="mes">
        <p>您注册的手机号为：<span class="phone"></span></p>
        <p>请设置您的密码</p>
    </div>
    <div class="regbox">
        <form method="post">
            <input type="password"  placeholder="请输入密码" id="pass">
            <input type="password"  placeholder="请输入确认密码" id="confirm">
            <label for="name">用户名</label>
            <input type="text" id="name" placeholder="请输入用户名">
            <label for="question">密保问题</label>
            <input type="text" id="question" placeholder="请输入密保问题">
            <label for="answer">密保答案</label>
            <input type="text" id="answer" placeholder="请输入密保答案">
            <p class="hint verify-text"></p>
        </form>
        <a class="btn" href="javascript:;">提交</a>
    </div>
</div>
<div class="footer">
    <div class="footer-are">
        <a href="javascript:;">简体</a>
        <span> | </span>
        <a href="javascript:;">繁体</a>
        <span> | </span>
        <a href="javascript:;">English</a>
        <span> | </span>
        <a href="javascript:;">常见问题</a>
    </div>
    <div class="footer-info">
        <p>艾家艾草公司版权所有-京ICP备10046444-京公网安备11010802020134号-京ICP证110507号</p>
    </div>
</div>
</body>
</html>
<script>
    var phone=$.cookie("user_phone");
    $('.phone').html(phone);
    $('#pass').blur(function(){
        if(!$(this).val()){
            $('.verify-text').html('密码不能为空');
        }else{
            $('.verify-text').html('');
        }
    });
    $('#confirm').blur(function(){
        if(!$(this).val()){
            $('.verify-text').html('再次输入的密码不能为空');
        }else{
            $('.verify-text').html('');
        }
        if($('#pass').val()!=$('#confirm').val()){
            $('.verify-text').html('两次密码不一致');
        }else{
            $('.verify-text').html('');
        }
    });
    $('#name').blur(function(){
        if(!$(this).val()){
            $('.verify-text').html('用户名不能为空');
        }else{
            $.ajax({
                url:'/user/check_valid.do',
                data:{
                    'str':$('#name').val(),
                    'type':'username'
                },
                type:'post',
                success:function(str){
                    if(str.status){
                        $('.verify-text').html(str.msg);
                    }else{
                        $('.verify-text').html('');
                    }
                },
                error:function(){

                }
            });
        }

    });
    $('#question').blur(function(){
        if(!$(this).val()){
            $('.verify-text').html('密保问题不能为空');
        }else{
            $('.verify-text').html('');
        }

    });
    $('#answer').blur(function(){
        if(!$(this).val()){
            $('.verify-text').html('密保答案不能为空');
        }else{
            $('.verify-text').html('');
        }

    });
    $('.btn').click(function(){
        if(!$('#pass').val() || !$('#confirm').val() || !$('#name').val() || !$('#question').val() || !$('#answer').val()){
            $('.verify-text').html('请填写完整');
        }
        var user_phone=$.cookie("user_phone");
        if(!user_phone){
            $('.verify-text').html('您的手机号已过期，请返回从新注册。');
        }else{
            $('.verify-text').html('');
        }
        if($('.verify-text').html()==''){

            var password=$('#pass').val();
            var name=$('#name').val();
            var question=$('#question').val();
            var answer=$('#answer').val();

            if(!user_phone ||!password ||!name ||!question||!answer ){
                return;
            }
            $.ajax({
                url:'/user/register.do',
                data:{
                    'username':name,
                    'password':password,
                    'phone':user_phone,
                    'question':question,
                    'answer':answer
                },
                type:'post',
                success:function(str){
                    if(str.status){
                        $('.verify-text').html(str.msg);
                    }else{
                        $('.verify-text').html('');
                        $('.btn').attr('href','register-ok.html');
                    }
                },
                error:function(){

                }
            })

        }

    });
</script>